/***************
 * Organization Projects Panel
 */
AIR2.Organization.Projects = function() {
    var p = new AIR2.UI.Panel({
        colspan: 1,
        title: 'Projects',
        showTotal: true,
        iconCls: 'air2-icon-project',
        storeData: AIR2.Organization.PRJDATA,
        url: AIR2.Organization.ORGURL + '/projects',
        itemSelector: '.air2-org-prj',
        tools: ['->', {
            xtype: 'air2button',
            air2type: 'CLEAR',
            iconCls: 'air2-icon-add',
            tooltip: 'New project',
            hidden: !AIR2.Organization.ORGDATA.authz.may_write,
            handler: function() {
                AIR2.Project.Create({
                    originEl: this.el,
                    org_uuid:AIR2.Organization.ORGUUID,
                    redirect: true  // go directly to new Project page on save
                });
            }
        }],
        tpl: new Ext.XTemplate(
            '<table>' +
              '<tr><th>PROJECT</th><th class="right">LAST UPDATED</th>' +
                '<th class="right">CREATED</th></tr>' +
              '<tpl for="."><tr class="air2-org-prj">' +
                '<td>{[AIR2.Format.projectName(values.Project,true)]}</td>' +
                '<td align="right">{[AIR2.Format.date(values.Project.prj_upd_dtim)]}</td>' +
                '<td align="right">{[AIR2.Format.date(values.Project.prj_cre_dtim)]}</td>' +
              '</tr></tpl>' +
            '</table>',
            {compiled: true, disableFormats: true}
        ),
        editModal: {
            allowAdd: false,
            width: 450,
            items: {
                xtype: 'air2liveeditor',
                url: AIR2.Organization.ORGURL + '/projects',
                sortField: 'prj_display_name',
                sortDir: 'ASC',
                pageSize: 50,
                hideButtons: true,
                tpl: new Ext.XTemplate(
                    '<table><tr class="air2-org-project">' +
                      '<td>{[AIR2.Format.projectName(values.Project,true)]}</td>' +
                      '<td align="right">{[AIR2.Format.dateLong(values.Project.prj_upd_dtim)]}</td>' +
                      '<td align="right">{[AIR2.Format.dateLong(values.Project.prj_cre_dtim)]}</td>' +
                    '</tr></table>',
                    {compiled: true, disableFormats: true}
                )
            }
        }
    });

    return p;
}
